def delete_card(loc):
    print('删除名片')
    del system_list[loc]


def modify(loc):
    print('修改名片')
    print('1.【修改Tel】  2.【修改QQ】  3.【修改Email】 4.【全部修改】')
    call = int(input('请选择修改项：'))
    if call == 1:
        tel = input('请输入新号码：')
        system_list[loc]['tel'] = tel
    elif call == 2:
        qq = input('请输入新QQ：')
        system_list[loc]['QQ'] = qq
    elif call == 3:
        mail = input('请输入新邮箱：')
        system_list[loc]['mail'] = mail
    elif call == 4:
        new_card()
        del system_list[loc]


def print_card(i):
    print('*' * 50)
    print('name：  ' + i['name'])
    print('tel：  ' + i['tel'])
    print('QQ：  ' + i['QQ'])
    print('Email：  ' + i['mail'])
    print('*' * 50)


def search(s_name):
    print('正在查找%s的信息' % s_name)
    for i in range(len(system_list)):
        if (system_list[i]['name'] == s_name):
            loc = i
            return loc


def show_all():
    print('正在打印全部用户全部...')
    for i in system_list:
        print('*' * 50)
        print('name：  ' + i['name'])
        print('tel：  ' + i['tel'])
        print('QQ：  ' + i['QQ'])
        print('Email：  ' + i['mail'])
        print('*' * 50)


def new_card():
    print('新建名片')
    name = input('请输入姓名: ')
    tel = input('请输入电话号码: ')
    QQ = input('请输入QQ号: ')
    mail = input('请输入邮件: ')
    card_dict = {}
    card_dict['name'] = name
    card_dict['tel'] = tel
    card_dict['QQ'] = QQ
    card_dict['mail'] = mail
    print('新建名片成功！')
    print(card_dict)
    system_list.append(card_dict)


if __name__ == '__main__':
    print('*' * 50)

    print(' ' * 15 + '名片管理系统1.0')
    print()
    print('1. 新建名片')
    print('2. 显示全部')
    print('3. 查询名片')

    print()

    print('0. 退出系统')
    print('*' * 50)
    print('请输入操作编号：')
    num = int(input())
    system_list = []

    while (num != 0):
        if num == 1:
            new_card()
        elif num == 2:
            show_all()
        elif num == 3:
            command = input('请输入要查询的用户名称: ')
            loc = search(command)
            print_card(system_list[loc])
            print('1.【 修改 】      2.【删除】    3.【返回主目录】')
            call_search = int(input('请输入操作编号：'))
            if call_search == 1:
                modify(loc)
            elif call_search == 2:
                delete_card(loc)
            elif call_search == 3:
                print('正在返回主目录...')
            else:
                print('请检查输入')


        else:
            print('更多功能，敬请期待')
        print('请输入操作编号：')
        num = int(input())
